import axios from "axios";


axios.defaults.baseURL = 'http://localhost:8080/api/'

//登录
export const loginAPI=(loginData)=>{
    return axios.post(`auth/login`,loginData)
}

//注册
export const registerAPI=(registerData)=>{
    return axios.post(`auth/register`,registerData)
}

//************************************商家方法*******************************
//获取商家的门店列表
export const listMyShopsAPI=(token)=>{
    return axios.get(`business/listMyShops?token=${token}`)
}
//获取商家的商品列表
export const listMyItemsAPI=(token)=>{
    return axios.get(`business/listMyItems?token=${token}`)
}
//创建门店
export const createShopAPI=(token,shopData)=>{
    return axios.post(`business/createShop?token=${token}`,shopData)
}
//创建商品
export const createItemAPI=(token,itemData)=>{
    return axios.post(`business/createItem?token=${token}`,itemData)
}
//获取一个门店的相关信息
export const getShopByIdAPI=(token,shopData)=>{
    const params = new URLSearchParams(shopData)
    return axios.get(`shop/getShopById?token=${token}&${params.toString()}`)
}
//上架一个商品（未存在）
export const createShopItemAPI=(token,ShopItemData)=>{
    return axios.post(`shop/createShopItem?token=${token}`,ShopItemData)
}
//获取门店的商品
export const listMyShopItemsAPI=(token,shopId)=>{
    return axios.get(`shop/listMyShopItems?token=${token}&id=${shopId}`)
}

//修改商品状态
export const updateShopItemStateAPI=(token,formDate)=>{
    return axios.post(`shop/updateShopItemState?token=${token}`,formDate)
}
//获取一个门店的所有订单
export const getPaidOrderByOrderStateAPI=(token,queryData)=>{
    const params = new URLSearchParams(queryData)
    return axios.get(`shop/getMyShopOrder?token=${token}&${params.toString()}`)
}
//修改订单状态
export const updateOrderByOrderStateAPI=(token,formDate)=>{
    return axios.post(`shop/updateOrderState?token=${token}`,formDate)
}
//***************************用户方法*******************************

//获取首页所有门店
export const getAllIndexShopsAPI=(token)=>{
    return axios.get(`shop/getAllShops?token=${token}`)
}
//获取顾客门店商品(已上架)
export const getShopItemByShopWithCustomerAPI=(token,shopId)=>{
    return axios.get(`shop/getShopItemByShop/${shopId}?token=${token}`)
}

//获取我在门店的未支付订单
export const getOrderByShopAPI=(token,shopId)=>{
    return axios.get(`customer/getOrderByShop/${shopId}?token=${token}`)
}
//下单
export const placeOrderAPI=(token,data)=>{
    return axios.post(`customer/placeOrder?token=${token}`,data)
}
//获取全部订单
export const getMyOrdersAPI=(token)=>{
    return axios.get(`customer/getMyOrders?token=${token}`)
}

//用户获取某个订单
export const getOrderByIdAPI=(token,orderId)=>{
    return axios.get(`order/getOrderById/${orderId}?token=${token}`)
}

//用户支付订单
export const payOrderAPI=(token,orderId)=>{
    return axios.post(`customer/payOrder/${orderId}?token=${token}`)
}

//用户删除未支付订单
export const deleteOrderAPI=(token,orderId)=>{
    return axios.post(`customer/cancelOrder/${orderId}?token=${token}`)
}

